﻿using Jizsoft.JFrame.Modeling.Domain.Entities;
using Jizsoft.JFrame.Modeling.Domain.Services;
using Jizsoft.JFrame.Result;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Web.Http;

namespace Jizsoft.JFrame.Modeling.Web.Api
{
    public class FieldTypeController : ApiController
    {
        [HttpGet]
        public PagedResult<FieldType> List(Guid categoryId, int page, int limit)
        {
            return new QueryService().QueryFieldTypeList(categoryId, page * limit, limit);
        }

        [HttpGet]
        public ListResult<FieldTypeCategory> CategoryList()
        {
            return new QueryService().QueryFieldTypeCategoryList();
        }

        [HttpGet]
        public ListResult<DataType> DataTypeList()
        {
            return new QueryService().QueryDataTypeList();
        }
        //[HttpGet]
        //public PagedResult<FieldType> List(ListParameter parameter)
        //{
        //    return new QueryService().QueryFieldTypeList(parameter.CategoryId, parameter.Page * parameter.Limit, parameter.Limit);
        //}

        [HttpPost]
        public Jizsoft.JFrame.Result.ServiceResult Create(CreateParameter parameter)
        {
            return new CreateService().CreateFieldType(parameter.CategoryId, parameter.Code, parameter.Caption, parameter.DataType, parameter.MinLength, parameter.MaxLength, parameter.ValidationRegex, parameter.Description);
        }

        public class CreateParameter
        {
            public Guid CategoryId;
            public string Code;
            public string Caption;
            public Guid DataType;
            public int? MinLength;
            public int? MaxLength;
            public string ValidationRegex;
            public string Description;
        }
    }
}
